<?php
class m_materi extends CI_Model
{
	public $table = 'materi';
	public $primary_key = 'mat_id';
	
	function get_data(){
		$this->db->select("*");
		$this->db -> from($this->table);

		$query = $this -> db -> get();
		
		return $query->row_array();		
	}
	
	function get_data_by_id($id){
		$this->db->select("*");
		$this->db -> from($this->table);
		$this -> db -> where($this->primary_key, $id);

		$query = $this -> db -> get();
		
		return $query->row_array();		
	}
	
	function get_data_with_mp($where=null){
		$this->db->select("*");
		$this->db->from($this->table);
		$this->db->join('mata_pelajaran', 'mata_pelajaran.mp_id = materi.mp_id', 'inner');
		$this->db->join('kelas_materi', 'kelas_materi.mat_id = materi.mat_id', 'inner');
		$this->db->join('siswa', 'siswa.kl_id = kelas_materi.kl_id', 'inner');
		if($where)$this->db->where($where);
	
		$query = $this->db->get();
	
		return $query->result();		
	}
	
	function insert($value){
		$this->db->insert($this->table, $value);
		return mysql_insert_id();
	}
	
	function update($value, $where){
		return $this->db->update($this->table, $value, $where);
	}
	
	function delete($where){
		$query = $this->db->get_where($this->table, $where);
		$row = $query->row();	
		if($this->db->delete($this->table, $where)) return $row->mat_file;
		else return false;
	}
}
?>